package com.blogsoho.taurus.controller;

import com.blogsoho.taurus.constants.URIMapping;
import com.blogsoho.taurus.vm.ResponseWrapper;
import com.blogsoho.taurus.vo.ContentVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by 16978 on 2017/6/24.
 */
@Controller
@RequestMapping(URIMapping.BLOG)
public class SingleController extends BaseController {

    public static final String SINGLE = "{id:\\d+}";

    @GetMapping(SINGLE)
    public String single(ModelMap model, @PathVariable int id) throws Exception {
        model.addAttribute("category", categoryService.getAllCategory());
        ResponseWrapper<ContentVO> responseWrapper = contentService.getContentById(id);
        if (responseWrapper.isSuccess()) {
            model.addAttribute("content", responseWrapper.getData());
        }
        return "single";
    }
}
